/*
 * @Author: lsmi
 * @Date: 2021-08-11 21:55:09
 * @LastEditors: lsmi
 * @LastEditTime: 2021-08-11 22:59:41
 * @FilePath: \book-base-webpack\webpack.config.js
 */
const path = require('path')
// extract-text-webpack-plugin 从js提取css已经失效
// const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const resolve = (p) => path.resolve(__dirname, p)


module.exports = {
  mode: 'development',
  entry: resolve('./src/main.js'),
  output: {
    filename: 'main.js',
    path: resolve('./dist/')
  },
  devServer: {
    contentBase: resolve('./dist/'),
    compress: true,
    port: 9000
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        // use: [
        //   'style-loader',
        //   {
        //     loader: 'css-loader', options: {
        //       sourceMap: true
        //     }
        //   }
        // ]
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader'
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      // filename: `[name]_[contenthash:4].css`
      filename: 'main.css'
    })
  ]
}